package codegen.groovy.graphnetwork.graphics

import groovy.swing.j2d.GraphicsBuilder
import java.awt.Cursor
import javax.swing.JComponent;
import codegen.graphnetwork.model.*

/** 
*The place holder Graph implementation for testing 
*replace by JUNG
*/
public class GraphDisplayer{
    def gb = new GraphicsBuilder()
    JComponent parent;
  
    //
    def linksDisplayList=[]
    def nodesDisplayList=[]
    
    public display(JComponent parent,Graph g){
        this.parent = parent;
        def group1=gb.group{
            rect(x: 0, y: 0, width: 640, height: 480, fill: color(red:220,green:220,blue:220));
        }
        
        g.links.eachWithIndex{link,i->
            def linkDisplay = new LinkDisplay(link)
            linksDisplayList<<linkDisplay
            linkDisplay.parent = this
            group1<<linkDisplay.getLinkShape();
        }
        g.nodes.eachWithIndex{node,i->
            def nodeDisplay = new NodeDisplay(node)
            nodeDisplay.parent = this
            nodesDisplayList<<nodeDisplay
            group1<<nodeDisplay.getNodeShape();
        }

        return group1;
    }
    
    public update(){

        graphChange()
    }
    def listeners=[]
    
    public def addGraphChangeListener(def listener){
        listeners<<listener
    }
    public void graphChange(){
        listeners.each{

            it.graphChange()

        }
    }
    public setSelected(Node n){
        
    }
    



}